<template>
    <div>
        <van-nav-bar title="个人资料" left-arrow @click-left="onClickLeft" />
        <div style="border: 5px  solid  ;margin: 20px; border-color: #1989fa;border-radius:10px">
            <van-field v-model="form.usernick" :readonly="readonly" label="公司" placeholder="请填写" input-align="right" />
            <van-field v-model="form.username" :readonly="readonly" label="姓名" placeholder="请填写" input-align="right" />
        </div>
        <div style="margin: 20px;"> <van-button :disabled ="readonly" @click="local()" type="info" size="large">确定信息</van-button>
        </div>

    </div>
</template>

<script>
export default {
    data() {
        return {
            form: {
                usernick: '',
                username: ''
            },
            readonly: false

        };
    },
    created() {
        this.getuser()
    },
    methods: {
        getuser() {
            if (JSON.parse(localStorage.getItem('choujianguser'))) {
                const form = JSON.parse(localStorage.getItem('choujianguser'))
                this.form.usernick = form.usernick
                this.form.username = form.username
                this.readonly = true
            } else {
                this.readonly = false
            }
        },
        onClickLeft() {
            this.$router.go(-1)
        },
        local() {
            this.$dialog.confirm({
                message: '请确认你的信息，一旦提交无法更改',
            })
                .then(() => {
                    localStorage.setItem('choujianguser', JSON.stringify(this.form));
                    this.$toast('信息确认成功！');
                    this.readonly = true
                    this.$router.go(-1)
                })
                .catch(() => {
                    // on cancel
                });
        },
    },
}
</script>

<style scoped></style>